home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ray Dream Studio
/
Ray Dream Studio (CDRAYD1) (Ray Dream) (1995).iso
/
DREAMSDK.WIN
/
INCLUDE
/
RDARRAY.H
< prev
next >
Wrap
C/C++ Source or Header
|
1995-06-21
|
2KB
|
74 lines
/* $Id: rdarray.h 1.1 1994/10/29 00:41:45 Yann Exp $ */
/*$RDGNU$*/
#ifndef __RDARRAY__
#define __RDARRAY__
#ifndef __MTYPES__
#include "Mtypes.h"
#endif
class RDArrayIterator;
typedef long RDArrayIndex;
class RDArray {
private:
char* fData;
long fSize;
long fAllocSize;
short fElementSize;
short fAlignedSize;
public:
enum {kUnusedIndex=0,kBlockSize=10,kAlign=2}; // Align on words
RDArray(short elementSize);
~RDArray();
RDArray* Clone();
void* Next(void *current) const {return ((char *)current)+fAlignedSize;}
void* Prev(void *current) const {return ((char *)current)-fAlignedSize;}
long GetSize() const {return(fSize);}
void FreeAll(void (*howTo)(void*) );
void FreeElement(void (*howTo)(void*) , long i);
void Delete(long i); //Does not free FHObj
void DeleteAll();
long GetEqualItemNo(void* item);
void* First() const {return fData;}
void* Last() const;
void InsertFirst(void* item);
void InsertLast(void* item) {if (fSize==fAllocSize) MakeDataLarger();AtPut(++fSize,item);}
void AtPut(long index, void* item); //Does not free old item
void* At(long i) const {return fData+(i-1)*fAlignedSize;}
void* AtCheckedOrZero(long i) const;
void InsertBefore(long i, void* item);
void InsertAfter(long i, void* item);
void CopyItems(RDArray* fromList, long firstIndex, long nbItems, long insertIndex);
void Each(void(*DoToItem)(void*, void*), void* staticLink);
void* FirstThat(unsigned char(*TestItem)(void*, void*) , void* staticLink);
void PreAllocate(long nbElements, Boolean setSize=false);
void FreeData(void (*howTo)(void*) ); // same as FreeAll()
long GetIdentityItemNo(void* item); // same as GetEqualItemNo()
void DeleteElementsAt(long i, long nb);
private:
void MakeDataLarger();
friend class RDArrayIterator;
};
class RDArrayIterator {
public:
RDArrayIterator(RDArray *array) {fArray=array;fIndex=1;fCurrent=fArray->fData;}
void Reset() {fIndex=1;fCurrent=fArray->fData;}
void* First() {fIndex=1;return fCurrent=fArray->fData;}
void* Next() {fIndex++;return fCurrent+=fArray->fAlignedSize;}
Boolean More() {return (fIndex<=fArray->fSize);}
long GetIndex() {return fIndex;}
private:
RDArray *fArray;
char *fCurrent;
long fIndex;
};
#endif